# _*_ coding: utf-8 _*_
#!/usr/bin/env python

#      ___________________
#  ___| Modulbeschreibung \_________________________________________________________________________
# | Über die Netzwerkklasse können der Server und der Client einfach gestartet und beendet werden
# |__________________________________________________________________| Zuständigkeit [Jannik |____

# ...
import client
import server
import thread

class Network(object):
	'''Der ServerManager dient dem Verwalten des Servers'''
	
	def __init__(self):
		self.players = 8
		
	def setOptions(self, players):
		pass
	
	def getPlayernumber(self):
		return self.client.playernumber

	def runClient(self, race, server = "localhost", port = 50000):
		self.client = client.Client(race, server, port)
		#if self.client.connected:
		thread.start_new_thread(self.client.run,() )
		#	print "erfolg"
		#	return True
		#else: 
		#	print "fehler"
		#	return False
		
	def syncData(self):
		self.client.syncData()
	
	def sendKeys(self, keys):
		self.client.sendKeys(keys)
		
	def setServerOptions(self, players):
		self.players = players

	def runServer(self,ip="localhost",port=50000):
		#self.server = server.startServer()
		self.server = server.Start(ip,port)
		thread.start_new_thread(self.server.run,())
	
	def stopServer(self):
		self.server.stopServer()
		
	def getPlayerInf(self):
		return self.client.getPlayerInf()

	def getRaceState(self):
		return  self.client.getRaceState()

	def startRace(self):
		self.server.startRace()
	
	def conSucessfull(self):
		return self.client.conSucessfull()
	
	def sendFinish(self):
		self.client.sendFinish()
	
	def stopClient(self):
		self.client.stopClient()
	
if __name__ == '__main__': 
	server = server.Start()
	thread.start_new_thread(server.run,())
	server.startRace()
	server.stopServer()